/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author luosisi
 * Date: 2010-7-5 下午04:21:59
 */
package com.ccxe.manage.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ccxe.manage.dao.CustomerDAO;
import com.ccxe.manage.dao.impl.CustomerDaoImpl;
import com.ccxe.manage.model.CustomerBean;
import com.ccxe.manage.service.CustomerManager;

/**
 * @author luosisi
 *customer的增、删、改、查 操作
 */
public class CustomerManagerImpl implements CustomerManager {
	
    private CustomerDAO dao=new CustomerDaoImpl();
    
	public int addCustormer(CustomerBean customer) {
		try {
			if(customer!=null){
				return dao.addCustormer(customer);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	public int deleteCustomer(String cid) {
		try {
			if(cid!=null&&!cid.equals("")){
				return dao.deleteCustomer(cid);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 条件查询, val: 值 , field:字段
	 */
	public List<CustomerBean> getByCondition(String val) {
		List<CustomerBean> list=new ArrayList<CustomerBean>();
		try {
			if(val!=null&&val.length()>0){
				list=dao.getByCondition(val);
			}else{
				list=dao.getByCondition(null);
			}
			if(list!=null&&list.size()>0) return list;
		} catch (Exception e) {
			list=null;
			e.printStackTrace();
		}
		return null;
	}

	public CustomerBean getById(String cid) {
		CustomerBean cb=null;
		try {
			if(cid!=null&&cid.length()>0)
				cb=dao.getById(cid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cb;
	}

	/**
	 * 更新客户
	 */
	public int updateCustomer(CustomerBean c) {
		try {
			if(c!=null){
				return dao.updateCustomer(c);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	/**
	 * 检查客户名字是否可用
	 * 返回true表示不存在,用户名可用
	 */
	public boolean isExsitID(String cid) {
		CustomerBean cb=this.getById(cid);
		return cb==null;
	}

	
}
